package com.moyq5.mvc.maker.test.bean;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.StringType;

import com.moyq5.mvc.framework.encrypt.JSON;
import com.moyq5.mvc.maker.test.bean.custom.IotBrandDeviceTcpRule;

/**
 * 品牌终端数据协议定制规则
 * @author Moyq5
 * @date 2018年8月28日
 */
public class IotBrandDeviceTcpRuleUserType extends AbstractJsonUserType implements Serializable {

	private static final long serialVersionUID = 1L;

	@Override
	public Object nullSafeGet(ResultSet arg0, String[] arg1, SharedSessionContractImplementor arg2, Object arg3)
			throws HibernateException, SQLException {
		if (null == arg0.getObject(arg1[0])) return null;
		String value = String.valueOf(StringType.INSTANCE.get(arg0, arg1[0], arg2));
		return JSON.toObject(value, IotBrandDeviceTcpRule.class);
	}

	@Override
	public Class<?> returnedClass() {
		return IotBrandDeviceTcpRule.class;
	}

}
